package service.credit.impl;

import dao.LcBankDao;
import java.util.ArrayList;

import java.util.List;

import dao.CompanybasicDao;
import dao.CompanymanageDao;
import dao.CompanypledgerDao;
import dao.PersonalbasicDao;

import model.company.Companybasic;
import model.company.Companymanage;
import model.company.Companypledger;
import model.credit.Lcbank;
import model.personal.Personalbasic;
import service.credit.CreditApplyEnterpriseAjaxService;
import vo.CreditEnsurePeopleBean;
import vo.CreditHypothecateThingBean;
import vo.CreditPledgeThingBean;

public class CreditApplyEnterpriseAjaxServiceImpl implements
		CreditApplyEnterpriseAjaxService {
	private PersonalbasicDao personalbasicDao;
	private CompanybasicDao companybasicDao;
	private CompanymanageDao companymanageDao;
	private CompanypledgerDao companypledgerDao;
	private LcBankDao LcBankDao;

	/* 得到保证人的信息 */
	@Override
	public List<CreditEnsurePeopleBean> getOneEnterpriseList(
			Integer custommainid) {
		List<CreditEnsurePeopleBean> creditEnsurePeopleList = new ArrayList<CreditEnsurePeopleBean>();
		List<Companybasic> allEnsureE = this.companybasicDao.findAll();
		List<Personalbasic> allEnsureP = this.personalbasicDao.findAll();
		if (allEnsureE != null) {
			for (Companybasic _companybasic : allEnsureE) {
				CreditEnsurePeopleBean _creditEnsurePeopleBean = new CreditEnsurePeopleBean();
				List<Lcbank> lcBankList = this.LcBankDao.findModel("cid = " + _companybasic.getId() + " and type = 2");
				if(lcBankList != null){
					_creditEnsurePeopleBean.setForeginBank(lcBankList.get(0).getSaveaccount());
					_creditEnsurePeopleBean.setBasicBank(lcBankList.get(0).getBankname());
				}
				_creditEnsurePeopleBean.setPeopleId(_companybasic.getId());
				_creditEnsurePeopleBean.setPeopleName(_companybasic.getName());
				_creditEnsurePeopleBean.setRelationpeopletype(2);
				creditEnsurePeopleList.add(_creditEnsurePeopleBean);
			}
		}
		
		if(allEnsureP != null){
			for (Personalbasic _personalbasic : allEnsureP) {
				CreditEnsurePeopleBean _creditEnsurePeopleBean = new CreditEnsurePeopleBean();
				List<Lcbank> lcBankList = this.LcBankDao.findModel("cid = " + _personalbasic.getId() + " and type = 1");
				if(lcBankList != null){
					_creditEnsurePeopleBean.setForeginBank(lcBankList.get(0).getSaveaccount());
					_creditEnsurePeopleBean.setBasicBank(lcBankList.get(0).getBankname());
				}
				_creditEnsurePeopleBean.setPeopleId(_personalbasic.getId());
				_creditEnsurePeopleBean.setPeopleName(_personalbasic.getName());
				_creditEnsurePeopleBean.setRelationpeopletype(1);
				creditEnsurePeopleList.add(_creditEnsurePeopleBean);
			}
		}
		return creditEnsurePeopleList;
	}

	/* 得到抵押信息 */
	@Override
	public List<CreditHypothecateThingBean> getOneCreditHypothecateThingList(
			Integer custommainid) {
		List<CreditHypothecateThingBean> creditHypothecateThingBeanList = new ArrayList<CreditHypothecateThingBean>();
		List<Companypledger> companypledgerEnterpriseList = this.companypledgerDao
				.findModel("typerelation = 1 and typecustom = 2");
		List<Companypledger> companypledgerPersonal = this.companypledgerDao
				.findModel("typerelation = 1 and typecustom = 1");
		if (companypledgerEnterpriseList != null) {
			for (Companypledger _companypledger : companypledgerEnterpriseList) {
				CreditHypothecateThingBean _creditHypothecateThingBean = new CreditHypothecateThingBean();
				_creditHypothecateThingBean.setPeopleid(_companypledger.getCid());
				if (this.companybasicDao.findOne("id", _companypledger.getCid()) != null) {
					_creditHypothecateThingBean
							.setPeopleName(this.companybasicDao.findOne("id",
									_companypledger.getCid()).getName());
				}
				_creditHypothecateThingBean.setThingName(_companypledger
						.getCollateralname());
				if(_companypledger.getCollateralvalueidentification() == null){
					_creditHypothecateThingBean.setPrice(0);
				}else{
					_creditHypothecateThingBean.setPrice(_companypledger
							.getCollateralvalueidentification());
				}
				_creditHypothecateThingBean.setRelationpeopletype(2);
				_creditHypothecateThingBean.setId(_companypledger.getId());
				creditHypothecateThingBeanList.add(_creditHypothecateThingBean);
			}
		}
		if (companypledgerPersonal != null) {
			for (Companypledger _companypledger : companypledgerPersonal) {
				CreditHypothecateThingBean _creditHypothecateThingBean = new CreditHypothecateThingBean();
				_creditHypothecateThingBean.setId(_companypledger.getId());
				_creditHypothecateThingBean.setPeopleid(_companypledger.getCid());
				if (this.personalbasicDao
						.findOne("id", _companypledger.getCid()) != null) {
					_creditHypothecateThingBean
							.setPeopleName(this.personalbasicDao.findOne("id",
									_companypledger.getCid()).getName());
				}
				_creditHypothecateThingBean.setThingName(_companypledger
						.getCollateralname());
				if(_companypledger.getCollateralvalueidentification() == null){
					_creditHypothecateThingBean.setPrice(0);
				}else{
					_creditHypothecateThingBean.setPrice(_companypledger
							.getCollateralvalueidentification());
				}
				_creditHypothecateThingBean.setRelationpeopletype(1);
				creditHypothecateThingBeanList.add(_creditHypothecateThingBean);
			}
		}
		return creditHypothecateThingBeanList;
	}

	/* 得到质押信息 */
	@Override
	public List<CreditPledgeThingBean> getOneCreditPledgeThingBeanList(
			Integer custommainid) {
		List<CreditPledgeThingBean> creditPledgeThingBeanList = new ArrayList<CreditPledgeThingBean>();
		List<Companypledger> companypledgerEnterpriseList = this.companypledgerDao
				.findModel("typerelation = 2 and typecustom = 2");
		List<Companypledger> companypledgerPersonal = this.companypledgerDao
				.findModel("typerelation = 2 and typecustom = 1");
		if (companypledgerEnterpriseList != null) {
			for (Companypledger _companypledger : companypledgerEnterpriseList) {
				CreditPledgeThingBean _creditPledgeThingBean = new CreditPledgeThingBean();
				_creditPledgeThingBean.setId(_companypledger.getId());
				_creditPledgeThingBean.setPeopleid(_companypledger.getCid());
				if (this.companybasicDao.findOne("id", _companypledger.getCid()) != null) {
					_creditPledgeThingBean.setPeopleName(this.companybasicDao
							.findOne("id", _companypledger.getCid()).getName());
				}
				_creditPledgeThingBean.setThingName(_companypledger
						.getCollateralname());
				if(_companypledger.getCollateralvalueidentification() == null){
					_creditPledgeThingBean.setPrice(0);
				}else{
					_creditPledgeThingBean.setPrice(_companypledger
							.getCollateralvalueidentification());
				}
				_creditPledgeThingBean.setRelationpeopletype(2);
				creditPledgeThingBeanList.add(_creditPledgeThingBean);
			}
		}
		if (companypledgerPersonal != null) {
			for (Companypledger _companypledger : companypledgerPersonal) {
				CreditPledgeThingBean _creditPledgeThingBean = new CreditPledgeThingBean();
				_creditPledgeThingBean.setId(_companypledger.getId());
				_creditPledgeThingBean.setPeopleid(_companypledger.getCid());
				if (this.personalbasicDao
						.findOne("id", _companypledger.getCid()) != null) {
					_creditPledgeThingBean.setPeopleName(this.personalbasicDao
							.findOne("id", _companypledger.getCid()).getName());
				}
				_creditPledgeThingBean.setThingName(_companypledger
						.getCollateralname());
				if(_companypledger.getCollateralvalueidentification() == null){
					_creditPledgeThingBean.setPrice(0);
				}else{
					_creditPledgeThingBean.setPrice(_companypledger
							.getCollateralvalueidentification());
				}
				_creditPledgeThingBean.setRelationpeopletype(1);
				creditPledgeThingBeanList.add(_creditPledgeThingBean);
			}
		}
		return creditPledgeThingBeanList;
	}

	public PersonalbasicDao getPersonalbasicDao() {
		return personalbasicDao;
	}

	public void setPersonalbasicDao(PersonalbasicDao personalbasicDao) {
		this.personalbasicDao = personalbasicDao;
	}

	public CompanybasicDao getCompanybasicDao() {
		return companybasicDao;
	}

	public void setCompanybasicDao(CompanybasicDao companybasicDao) {
		this.companybasicDao = companybasicDao;
	}

	public CompanymanageDao getCompanymanageDao() {
		return companymanageDao;
	}

	public void setCompanymanageDao(CompanymanageDao companymanageDao) {
		this.companymanageDao = companymanageDao;
	}

	public CompanypledgerDao getCompanypledgerDao() {
		return companypledgerDao;
	}

	public void setCompanypledgerDao(CompanypledgerDao companypledgerDao) {
		this.companypledgerDao = companypledgerDao;
	}

	public LcBankDao getLcBankDao() {
		return LcBankDao;
	}

	public void setLcBankDao(LcBankDao lcBankDao) {
		LcBankDao = lcBankDao;
	}

}
